﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace TypingG
{
    class tBoxStyle3:tBox
    {
        private Timer timer1 = new Timer();
        private int delay;
        public tBoxStyle3()
        {
            
            
        }
        public override void getStyle()
        {
                
                string content = StringRandom.getStRandom(400);
                LabelCollection(content);
                int distancex = 20;
                int distancey = 20;
                int endtoenter = this.Width / distancex;
                for (int i = 0; i < arrLabel.Count; i++)
                {
                    int div = (i * distancex) / this.Width;
                    int du = i % endtoenter;
                    ((Label)arrLabel[i]).Location = new System.Drawing.Point(distancex * du, 20 + distancey * div);
                    this.Controls.Add(((Label)arrLabel[i]));
                }
                this.KeyPress += new KeyPressEventHandler(tBoxStyle3_KeyPress);
                processbar();
                
                timer1.Start();
                timer1.Interval = 100;
                this.delay = StringRandom.Speed / 100;
                timer1.Tick += new EventHandler(timer1_Tick);
                
        }
        private int _index = 0;
        void tBoxStyle3_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (Convert.ToString(e.KeyChar) == ((Label)this.arrLabel[_index]).Text)
            {
                
                this.Clear();
                ((Label)this.arrLabel[_index]).ForeColor = System.Drawing.Color.Red;
                if (_index == 399)
                {
                    this.Enabled = false;
                    timer1.Stop();
                    AccInfo.increaseEXP(AccInfo.WILLHAVEEXP);
                    MessageBox.Show("YouWin.You Have " + Convert.ToString(AccInfo.WILLHAVEEXP) + " EXP");
                    this.Dispose();
                }
                _index++;
            }
            else
            {
                this.Clear();
                
            }
            
            
        }
        
        private int m = 0;
        void timer1_Tick(object sender, EventArgs e)
        {
            this.Focus();
            if (m == this.delay)
            {
                this.pBar.Increment(1);
                m = 0;
            }
            if (this.pBar.Value == this.pBar.Maximum)
            {
                timer1.Stop();
                this.Dispose();
            }
            m++;
        }
        
    }
}
